package com.ddm.controller.common;

import com.ddm.dto.page.PageQueryDTO;
import com.ddm.result.PageResult;
import com.ddm.result.Result;
import com.ddm.service.StandardService;
import com.ddm.vo.StandardDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 丁丁猫
 * @version 1.0
 */
@RestController("CommonStandardController")
@RequestMapping("/common/standard")
@Api(tags = "标准文档相关接口")
@Slf4j
public class StandardController {

    @Autowired
    private StandardService standardService;

    /**
     * 分页查询标准文档
     * @param pageQueryDTO
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询标准文档")
    public Result<PageResult> page(PageQueryDTO pageQueryDTO, @RequestParam(value = "level", required = false) String level) {
        log.info("根据关键词分页查询标准文档");
        pageQueryDTO.setLevelType(level);
        PageResult pageResult = standardService.pageQueryByKeyword(pageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询标准文档
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询标准文档")
    public Result<StandardDetailVO> getById(@PathVariable Long id) {
        log.info("根据id查询标准文档:{}",id);
        StandardDetailVO standardDetailVO = standardService.getStandardDetailById(id);
        return Result.success(standardDetailVO);
    }
}
